package com.huawo.opensdk.bean;

import androidx.annotation.NonNull;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.Iterator;

public class JsonArrayIterable implements Iterable<JSONObject> {

    private final JSONArray jsonArray;

    public JsonArrayIterable(JSONArray jsonArray) {
        this.jsonArray = jsonArray;
    }

    @NonNull
    @Override
    public Iterator<JSONObject> iterator() {
        return new Iterator<JSONObject>() {
            int index = 0;

            @Override
            public boolean hasNext() {
                return index < jsonArray.length();
            }

            @Override
            public JSONObject next() {
                return jsonArray.optJSONObject(index++);
            }
        };
    }

}